<?php

/**
 * The VehicleCore class is a controller of the Design Pattern.
 * 
 * @abstract LayoutPage
 * @author Cesar Augustus Silva <cesaraugustussilva@linuxmail.org>
 * @copyright Copyright (c) 2013, Cesar Augustus Silva
 * @license http://www.gnu.org/licenses/gpl.html GNU GPL v3.0
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <­http://www.gnu.org/licenses/>.
 */
class ProductCore extends LayoutPage {

    /** @var stdClass The data of the vehicle */
    public static $product;
    public static $product_owners;
    public static $pictures;
    public static $client;
    public static $phones;
    private static $id_product;
    public static $type;
    public static $lastproducts;

    public function setMedia() {
        parent::setMedia();
        Shell::addStyle(array('colorbox-responsive'));
        Shell::addScript(array('jquery.maskedinput.min', 'jquery.jcarousel.min', 'jquery.pikachoose.min', 'jquery.colorbox-min'));
    }

    public function preProcess() {
        parent::preProcess();        
        
        self::$id_product = $_GET['param'];

        /* pegando o codigo da empresa ou pessoa física */
        self::$product_owners = DbGet::products_owners(self::$id_product);
        
        if (self::$product = DbGet::product(self::$id_product)) {
            if (self::$product_owners->type == 'J') {
                self::$client = DbGet::enterprise(self::$product_owners->id_client);
            } else {
                self::$client = DbGet::customer(self::$product_owners->id_client);
            }
            self::$phones = DbGet::phones(self::$product_owners->id_client, self::$product_owners->type);
            self::$lastproducts = DbGet::products_latest(5, self::$product_owners->id_client, self::$product_owners->type, self::$id_product);
        }else{
            header("location:/");
        }
    }

    public function displayHeader() {
        global $_tag_title, $_metatag_description, $_metatag_keywords;

        $_tag_title = self::$product->name . ' | Goiautos.com.br';
        $_metatag_description = 'Somos um classificado de carros com experiência em divulgação de veículos online.';
        $_metatag_keywords = str_word_count(mb_strtolower('carros motos novos seminovos usados caminhões veículos classificados goiás quem somos', 'UTF-8'), 1, 'áéíóúàâêôçãõ0123456789');

        parent::displayHeader();
    }

    public function process() {
        parent::process();
        self::$pictures = DbGet::products_pictures(self::$id_product);
    }

    public function displayContent() {
        parent::displayContent();

        Shell::addWidget(array('new-search', 'side-menus'), 'sidebar-left');
        Shell::showPage('product');
    }

}